package com.stadium.controller;

import java.util.List;
import java.util.UUID;

import com.stadium.common.BaseResponse;
import com.stadium.dto.GameCategoryDto;
import com.stadium.service.GameCategorySV;
import com.stadium.vo.GameCategoryVo;
import com.stadium.vo.searchVo.GameCategorySearchVo;
import io.micrometer.core.instrument.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 赛事分类
 *
 * @author wsl
 * @email
 * @date 2021-05-04 09:39:10
 */
@RestController
@RequestMapping("/api/gamecategory")
@Api(tags = "赛事分类")
public class GameCategoryCL{
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private GameCategorySV gameCategorySV;

    @ApiOperation(value = "保存或修改")
    @PostMapping(value = "/v1/save")
    public BaseResponse save(@Validated GameCategoryVo gameCategoryVo) {
        try {
            if (gameCategoryVo.getId() == null ||gameCategoryVo.getId() == ""){
                    gameCategorySV.save(gameCategoryVo);
            }else{
                    gameCategorySV.update(gameCategoryVo);
            }
            return BaseResponse.ok();

        } catch (Exception e) {
            e.printStackTrace();
            return BaseResponse.error();
        }
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "/v1/delete")
    @ApiImplicitParams({@ApiImplicitParam(name="id",value="id")})
    public BaseResponse delete(@RequestParam(name = "id", required = true)String id) {
        try {
            gameCategorySV.delete(id);
            return BaseResponse.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return BaseResponse.error();
        }
    }


    @ApiOperation(value = "获得列表")
    @GetMapping(value = "/v1/query")
    public BaseResponse<List<GameCategoryDto>> query(@Validated GameCategorySearchVo searchVo) {
        try {
            if (StringUtils.isNotEmpty(searchVo.getSearchValue())) {
                searchVo.setSearchValue("%" + searchVo.getSearchValue() + "%");
            }
            List<GameCategoryDto> queryList = gameCategorySV.query(searchVo);
            int total = gameCategorySV.getCount(searchVo);
            return BaseResponse.ok(queryList, total);
        } catch (Exception e) {
            logger.error("日志失败！", e);
            return BaseResponse.error();
        }
    }

    /*@ApiOperation(value = "获得详情", notes = "获得详情")
    @GetMapping(value = "/v1/get")
    @ApiImplicitParams({@ApiImplicitParam(name="id",value="id")})
    public BaseResponse<GameCategoryDto> get(@RequestParam(name = "id", required = true)String id) {
        try {
                GameCategoryDto queryData = gameCategorySV.get(id);
            return BaseResponse.ok(queryData);
        } catch (Exception e) {
            logger.error("日志失败！", e);
            return BaseResponse.error();
        }
    }*/
}
